package domain.entities;

import java.util.Date;
import java.util.List;
import java.util.Set;
import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 * A data access object (DAO) providing persistence and search support for
 * ComiteDocencia entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see domain.entities.ComiteDocencia
 * @author MyEclipse Persistence Tools
 */

public class ComiteDocenciaDAO extends HibernateDaoSupport {
	private static final Logger log = LoggerFactory
			.getLogger(ComiteDocenciaDAO.class);
	// property constants
	public static final String AGREE_RECEIVING_DIRECTLY_FROM_SPONSOR = "agreeReceivingDirectlyFromSponsor";
	public static final String DOCUMENT_APPROVAL_DELAY = "documentApprovalDelay";
	public static final String HOW_OFTEN_THEY_MET = "howOftenTheyMet";
	public static final String LIST_OF_MEMBERS_NOT_PARTICIPATING = "listOfMembersNotParticipating";
	public static final String LIST_OF_MEMBERS_PARTICIPATING = "listOfMembersParticipating";
	public static final String NAME = "name";
	public static final String NEED_ECAPPROVAL = "needEcapproval";
	public static final String TIMELINE_TO_SUBMIT = "timelineToSubmit";

	protected void initDao() {
		// do nothing
	}

	public void save(ComiteDocencia transientInstance) {
		log.debug("saving ComiteDocencia instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(ComiteDocencia persistentInstance) {
		log.debug("deleting ComiteDocencia instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public ComiteDocencia findById(java.lang.Integer id) {
		log.debug("getting ComiteDocencia instance with id: " + id);
		try {
			ComiteDocencia instance = (ComiteDocencia) getHibernateTemplate()
					.get("domain.entities.ComiteDocencia", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List<ComiteDocencia> findByExample(ComiteDocencia instance) {
		log.debug("finding ComiteDocencia instance by example");
		try {
			List<ComiteDocencia> results = (List<ComiteDocencia>) getHibernateTemplate()
					.findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding ComiteDocencia instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from ComiteDocencia as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List<ComiteDocencia> findByAgreeReceivingDirectlyFromSponsor(
			Object agreeReceivingDirectlyFromSponsor) {
		return findByProperty(AGREE_RECEIVING_DIRECTLY_FROM_SPONSOR,
				agreeReceivingDirectlyFromSponsor);
	}

	public List<ComiteDocencia> findByDocumentApprovalDelay(
			Object documentApprovalDelay) {
		return findByProperty(DOCUMENT_APPROVAL_DELAY, documentApprovalDelay);
	}

	public List<ComiteDocencia> findByHowOftenTheyMet(Object howOftenTheyMet) {
		return findByProperty(HOW_OFTEN_THEY_MET, howOftenTheyMet);
	}

	public List<ComiteDocencia> findByListOfMembersNotParticipating(
			Object listOfMembersNotParticipating) {
		return findByProperty(LIST_OF_MEMBERS_NOT_PARTICIPATING,
				listOfMembersNotParticipating);
	}

	public List<ComiteDocencia> findByListOfMembersParticipating(
			Object listOfMembersParticipating) {
		return findByProperty(LIST_OF_MEMBERS_PARTICIPATING,
				listOfMembersParticipating);
	}

	public List<ComiteDocencia> findByName(Object name) {
		return findByProperty(NAME, name);
	}

	public List<ComiteDocencia> findByNeedEcapproval(Object needEcapproval) {
		return findByProperty(NEED_ECAPPROVAL, needEcapproval);
	}

	public List<ComiteDocencia> findByTimelineToSubmit(Object timelineToSubmit) {
		return findByProperty(TIMELINE_TO_SUBMIT, timelineToSubmit);
	}

	public List findAll() {
		log.debug("finding all ComiteDocencia instances");
		try {
			String queryString = "from ComiteDocencia";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public ComiteDocencia merge(ComiteDocencia detachedInstance) {
		log.debug("merging ComiteDocencia instance");
		try {
			ComiteDocencia result = (ComiteDocencia) getHibernateTemplate()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(ComiteDocencia instance) {
		log.debug("attaching dirty ComiteDocencia instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(ComiteDocencia instance) {
		log.debug("attaching clean ComiteDocencia instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static ComiteDocenciaDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (ComiteDocenciaDAO) ctx.getBean("ComiteDocenciaDAO");
	}
}